:- module(error_page,
	[
	    error_page/2,
	    problem/1
	], [pillow,assertions,regtypes,basicmodes]).

:- use_module(library(hiordlib), [map/3]).
:- use_module(library('pillow/pillow_types')).

:- regtype problem/1 # "Type for use in @pred{error_page/2}.".

:- comment(problem/1,"@includedef{problem/1}").

problem(empty(X)) :- atm(X).
problem(no_num(X)) :- atm(X).

:- comment(module,"This module generates an HTML page showing a list of
	error messages.").

:- true pred error_page(in(Problems), go(HTML)) :: list(problem) *
   html_term 

# "Generates an HTML page @var{HTML} for showing a list of problems
  @var{Problems} detected in the data introduced by the user in the
  search form page. It is used throughout the system to generate user
  friendly error messages when necessary.".

error_page(Problems, HTML):-
        HTML = [env(h2, [], 
	        ["There are some errors in the search input"]), ErrorDetail],
        ( Problems = [] ->
            ErrorDetail = []
        ;
            map(Problems, p_to_s, ProbStrs),
	    ErrorDetail = itemize(ProbStrs)
        ).

p_to_s(empty(terms), 
       ["No terms to search for.", 
        " Please enter some dictionary terms in the input box labeled \"",
        font([],b("Search terms")),
        "\" of the previous form.",
        "  You can use the menus to select them.", \\]):- !. 
p_to_s(no_num(num_match),
       ["The value in the input box labeled \"",
        font([],b("Maximum number of assemblies to return")),
        "\"is not a number.  Please correct it.", \\]):- !.
p_to_s(no_num(wpackagenumber), ["The weight for number of packages in the sort options is not a valid number.", \\]) :- !.
p_to_s(no_num(wunsatisfieddeps), ["The weight for unsatisfied dependencies in the sort options is not a valid number.", \\]) :- !.
p_to_s(no_num(wtighterassemblies), ["The weight for tighter assemblies in the sort options is not a valid number.", \\]) :- !.
p_to_s(no_num(wcapabilities), ["The weight for less number of capabilities in the sort options is not a valid number.", \\]) :- !.
p_to_s(no_num(wbestcapabilitiesratio), ["The weight for best capabilities ratio in the sort options is not a valid number.", \\]) :- !.
p_to_s(no_num(levelprec), ["The generalization level in the required capabilities is not a valid number.", \\]) :- !.
p_to_s(no_num(levelpost), ["The generalization level in the provided capabilities is not a valid number.", \\]) :- !.

p_to_s(_, "Unknown error code returned!").
